package com.md.facade;

import com.md.api.LogsApi;
import com.md.api.OpenLogsApi;
import com.md.application.service.logs.LogsApplicationService;
import com.md.config.Logs;
import com.md.model.system.CommonResult;
import com.md.request.OperationLogsRequest;
import com.md.request.QueryLogsRequest;
import com.md.request.QueryLogsTreeRequest;
import com.md.response.LogsResponse;
import com.md.response.LogsTreeResponse;
import com.md.response.QueryLogsResponse;
import com.md.response.SimplifyLogsTreeResponse;
import com.md.value.enums.OperationEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 刘骄阳
 * 2022-04-01 18:28
 */
@RestController
@RequiredArgsConstructor
public class LogsController implements LogsApi, OpenLogsApi {
  private final LogsApplicationService logsApplicationService;

  /**
   * 分页查询日志
   *
   * @param request 请求实体
   * @return 操作结果
   */
  @Override
  @Logs(title = "分页查询日志", operation = OperationEnum.SELECT)
  public CommonResult<QueryLogsResponse> selectPage(final QueryLogsRequest request) {
    return logsApplicationService.selectPage(request);
  }

  /**
   * 查询请求链路
   *
   * @param request 请求实体
   * @return 操作结果
   */
  @Override
  @Logs(title = "查询请求链路", operation = OperationEnum.SELECT)
  public CommonResult<LogsTreeResponse> selectTree(final QueryLogsTreeRequest request) {
    return logsApplicationService.selectTree(request);
  }

  @Override
  @Logs(title = "新增日志", operation = OperationEnum.INSERT)
  public CommonResult<LogsResponse> create(final OperationLogsRequest request) {
    return logsApplicationService.create(request);
  }

  @Override
  @Logs(title = "更新日志", operation = OperationEnum.UPDATE)
  public CommonResult<LogsResponse> update(final OperationLogsRequest request) {
    return logsApplicationService.update(request);
  }

  @Override
  @Logs(title = "查询树结构", operation = OperationEnum.SELECT)
  public CommonResult<SimplifyLogsTreeResponse> selectTreeMap(final QueryLogsTreeRequest request) {
    return logsApplicationService.selectTreeMap(request);
  }
}
